import cn.hutool.core.util.ClassUtil;
import com.google.common.collect.Maps;
import com.sl.core.engine.datasource.DataSourceManager;
import com.zaxxer.hikari.HikariDataSource;
import lombok.SneakyThrows;
import org.anyline.data.jdbc.runtime.JDBCRuntimeHolder;
import org.anyline.data.jdbc.util.DataSourceUtil;
import org.anyline.data.runtime.DataRuntime;
import org.anyline.metadata.Column;
import org.anyline.metadata.PrimaryKey;
import org.anyline.metadata.Table;
import org.anyline.metadata.type.init.StandardTypeMetadata;
import org.anyline.proxy.ServiceProxy;
import org.anyline.service.AnylineService;

import javax.sql.DataSource;
import java.util.Map;

public class B {


    @SneakyThrows
    public static void main(String[] args) {

        ClassUtil.loadClass("org.h2.Driver");
        DataSourceManager instance = DataSourceManager.INSTANCE;
        Map<String, Object> maps = Maps.newConcurrentMap();
        maps.put("url", "jdbc:h2:file:./db/h2;MODE=MYSQL;FILE_LOCK=NO");
        maps.put("driver", "org.h2.Driver");
        maps.put("username", "root");
        maps.put("password", "123456");
        maps.put("type", HikariDataSource.class.getName());
        DataSource dataSource = DataSourceUtil.build(maps);

        DataRuntime runtime = JDBCRuntimeHolder.instance().temporary(dataSource, null,null);
        AnylineService anylineService = ServiceProxy.temporary(dataSource);
        anylineService.getDao().setRuntime(runtime);

        Table table = new Table("originTransformName" + "_" + "destinationTransformName");
        Column column = new Column("id");
        column.setTypeMetadata(StandardTypeMetadata.BIGINT);
        column.autoIncrement(true);
        table.addColumn(column);

        PrimaryKey primaryKey = new PrimaryKey();
        primaryKey.addColumn(column);
        table.setPrimaryKey(primaryKey);
//        table.execute(false);

        anylineService.ddl().create(table);

        System.out.println(table.ddl());

    }
}
